//获取应用实例
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // winHeight:"",//窗口高度
        currentTab: 0, //预设当前项的值
        norecord: false,
        hiddenModal: true,
        swiperHeader: '',
        companylist: [], // 个人
        enterpriselist: [],
        platformcompanylist: [], // 平台个人数据
        platformenterpriselist: [], // 企业
        type: 0,
        list: []
    },
    details: function (e) {
        wx.navigateTo({
            url:'/pages/index/platform_activities/details/details?id=' + e.currentTarget.dataset.id
        })
    },
    // 是否点赞
    isPraise:function(e){
        let itemId = e.currentTarget.dataset.id,
            state = e.currentTarget.dataset.state ? 0 : 1,
            _this = this;
        app.util.ajax({
            url:'platform/zambia',
            data:{
                id:itemId,
                user_id:app.globalData.userInfo.user_id,
                state: state
            },
            success:function(data){
                _this.getData();
                _this.getPersonal();

            }
        })
    },
    listenerButton(e) {
        let _this = this;
        let formId = e.detail.formId,
            id = e.detail.target.dataset.member_id,
            listId = e.detail.target.dataset.list;
        wx.showModal({
            content: '是否申请',
            success: function(res) {
                if (res.confirm) {
                    app.util.ajax({
                        url: 'Platform/add_personal',
                        data: {
                            member_id:id,
                            user_id:app.globalData.userInfo.user_id,
                            form_id:formId,
                            id:listId
                        },
                        success: function(res) {
                            if (res.state === 1) {
                                wx.showToast({
                                    title: '你已经申请成功',
                                    icon: 'success',
                                    duration: 2000
                                })
                                setTimeout(function(){_this.getPersonal();},2000);
                            }
                            _this.setData({
                                type: 1
                            })
                        }
                    })
                }
            }
        })
    },
    //企业走访
    enterpriselist(e) {
        let _this = this;
        let id = e.detail.target.dataset.member_id;
        let listId = e.detail.target.dataset.list;
        let formId = e.detail.formId;
        wx.showModal({
            content: '是否申请',
            success: function(res) {
                if (res.confirm) {
                    app.util.ajax({
                        url: 'Platform/add_personal',
                        data: {
                            member_id: id,
                            user_id: app.globalData.userInfo.user_id,
                            form_id:formId,
                            id:listId
                        },
                        success: function(res) {
                            if (res.state === 1) {
                                wx.showToast({
                                    title: '你已经申请成功',
                                    icon: 'success',
                                    duration: 2000
                                })
                            }
                        }
                    })
                }
            }
        })
    },
    listenerConfirm() {
        this.setData({
            hiddenModal: true
        })
    },
    // 点击标题切换当前页时改变样式
    swichNav: function(e) {
        var cur = e.currentTarget.dataset.current;
        if (this.data.currentTab == cur) { return false; } else {
            this.setData({
                currentTab: cur
            })
            if (cur == 0 ) {
                this.getPersonal();
            }else{
                this.getPlatform();
            }
        } 
    },

    //平台活动个人获取数据
    getPersonal() {
        let _this = this;
        app.util.ajax({
            url: 'Platform/index',
            data: {
                user_id: app.globalData.userInfo.user_id
            },
            success: function(res) {
                if (res.company || res.enterprise) {
                    _this.setData({
                        companylist: res.company,
                        enterpriselist: res.enterprise
                    })
                }
            }
        })
    },

    //平台发布获取数据
    getPlatform() {
        let _this = this;
        app.util.ajax({
            url: 'Platform/platform',
            success: function(res) {
                _this.setData({
                    platformcompanylist: res.company,
                    platformenterpriselist: res.enterprise
                })
            }
        })
    },

    //平台申请走访
    listenerButtonss(e) {
        let _this = this;
        let id = e.detail.target.dataset.member_id;
        let listId = e.detail.target.dataset.list;
        let formId = e.detail.formId;
        wx.showModal({
            content: '是否申请',
            success: function(res) {
                if (res.confirm) {
                    app.util.ajax({
                        url: 'Platform/add_platform',
                        data: {
                            member_id: id,
                            user_id: app.globalData.userInfo.user_id,
                            form_id:formId,
                            id:listId
                        },
                        success: function(res) {
                            if (res.state === 1) {
                                wx.showToast({
                                    title: '你已经申请成功',
                                    icon: 'success',
                                    duration: 2000
                                })
                                setTimeout(function(){_this.getPersonal();},2000);
                            }
                        }
                    })
                }
            }
        })
    },
    //添加发布
    Release(e) {
        wx.navigateTo({
            url:'/pages/index/platform_activities/add_activeites/add_activeites'
        })      
    },
    // 查看名片
    seeUserCard(e){

        let id = e.currentTarget.dataset.id,
            type = e.currentTarget.dataset.type;
        wx.navigateTo({
            url:'/pages/user/personal/personal?id='+id+'&state='+type
        })
    },
    getData () {
        let _this = this;
        app.util.ajax({
            url: 'Platform/index',
            data: {
                user_id: app.globalData.userInfo.user_id 
            },
            success: function(res) {
                _this.setData({
                    list: res.visit,
                })
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        // this.getPersonal();
        this.getData();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    // 分享
    onShareAppMessage(res) {
        return {
            title: '广州大学校友会校友企业家专委会',
            path: '/pages/index/index'
        }
    },
})